#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDebug>
#include <QLabel>
#include <QPushButton>
#include <QDialog>
#include <QMessageBox>
#include <QPixmap>
#include <QColorDialog>
#include <QFontDialog>
#include <QMovie>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->actionopen,&QAction::triggered,this,[=](){
        QString str= QFileDialog::getOpenFileName(this,"打开文件","D:\\","gif(*.gif)");
        qDebug()<<str;
    });
    //向状态栏加入一个label
    QLabel* laber=new QLabel("我是一个状态标签",this);
    ui->statusbar->addWidget(laber);

    //向状态栏加入一个按钮
    QPushButton* button1=new QPushButton("显示模态对话框",this);
    ui->statusbar->addWidget(button1);


    //模态对话框，显示这个之后就不能操作其他窗口
    connect(button1,&QPushButton::clicked,this,[=](){
        QDialog qdl(this);
        qdl.exec();
    });


    QPushButton* button2=new QPushButton("显示非模态对话框",this);
    ui->statusbar->addWidget(button2);

    //非模态对话框，显示这个之后还可以操作其他窗口
    connect(button2,&QPushButton::clicked,this,[=](){
        QDialog* qdl=new QDialog(this);
        //设置关闭窗口之后就自动释放内存
        qdl->setAttribute(Qt::WA_DeleteOnClose);
        qdl->show();
    });


    QPushButton* button3=new QPushButton("Qt提示对话框",this);
    ui->statusbar->addWidget(button3);

    //Qt提示对话框
    connect(button3,&QPushButton::clicked,this,[=](){
        //默认显示主窗口的图标
        // QMessageBox::about(this,"qt的提示对话框","这是显示内容的地方");
        // QMessageBox message;
        // message.about(this,"qt的提示对话框","这是显示内容的地方");

        //不显示图标
        // QMessageBox message(QMessageBox::NoIcon,"qt对话框","内容");
        // message.exec();

        //显示其他图标
        // QMessageBox message(QMessageBox::NoIcon,"qt对话框","内容");
        // message.setWindowIcon(QIcon(":/Image2/Sunny.jpg"));
        // message.setIconPixmap(QPixmap(":/Image2/Frame.jpg"));
        // message.exec();


        //提示对话框里面的按钮操作定义
        //critical:是错误提醒
        int ret=QMessageBox::critical(this,"错误提醒","错误提醒内容",QMessageBox::Ok | QMessageBox::Open);
        if(ret==QMessageBox::Ok)
        {
            QMessageBox::about(this,"提示","你点击了OK");
        }
        else if(ret==QMessageBox::Open)
        {
            QMessageBox::about(this,"提示","你点击了open");
        }

    });


    //打开颜色盘，获取颜色信息
    QPushButton* button4=new QPushButton("颜色盘",this);
    ui->statusbar->addWidget(button4);
    connect(button4,&QPushButton::clicked,this,[=](){
        QColor qc=QColorDialog::getColor();
        qDebug()<<qc.red()<<qc.green()<<qc.blue();
    });

    //打开字体库
    QPushButton* button5=new QPushButton("字体库",this);
    ui->statusbar->addWidget(button5);
    connect(button5,&QPushButton::clicked,this,[=](){
        bool ok;
        QFont font=QFontDialog::getFont(&ok,this);
        if(ok)
        {
            qDebug()<<font.family()<<font.italic()<<font.pointSize()<<font.bold();
        }
    });


    //基础控件
    //list Widget--数据一行一行显示
    ui->listWidget->addItem("床前明月光，疑是地上霜");
    ui->listWidget->addItem("举头望明月，低头思故乡");

    //Table Widget--表
    //设置行列大小
    ui->tableWidget->setRowCount(5);//列
    ui->tableWidget->setColumnCount(3);//行

    //设置表头
    QStringList lista;
    lista<<"学号"<<"姓名"<<"年龄";
    ui->tableWidget->setHorizontalHeaderLabels(lista);
    lista<<"1"<<"小明"<<"18";
    ui->tableWidget->setItem(0,0,new QTableWidgetItem("1"));
    ui->tableWidget->setItem(0,1,new QTableWidgetItem("小明"));
    ui->tableWidget->setItem(0,2,new QTableWidgetItem("18"));

    //stacked widget 点击按钮，切换页面
    connect(ui->pushButton_2,&QPushButton::clicked,this,[=](){
        ui->stackedWidget->setCurrentIndex(1);
    });

    //Combo Box 下拉列表
    //一次加一个
    ui->comboBox->addItem("李白");
    //一次加多个
    QStringList list1;
    list1<<"杜甫"<<"欧阳修"<<"辛弃疾";
    ui->comboBox->addItems(list1);
    //加图标
    ui->comboBox->addItem(QIcon(":/Image2/Luffy.png"),"路飞");

    //看看每次选择了什么
    connect(ui->comboBox,&QComboBox::currentIndexChanged,this,[=](){
        qDebug()<<ui->comboBox->currentIndex();//打印当前所指的下标
        qDebug()<<ui->comboBox->currentText();//打印当前内容
    });

    //给标签加一个静态图标
    ui->label->setPixmap(QPixmap(":/Image2/face.png"));

    //加动态图片
    QMovie* movie=new QMovie(":/Image2/mario.gif");
    ui->label->setMovie(movie);
    movie->start();//注意动态图片要手动启动
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    ui->stackedWidget->setCurrentIndex(0);
}










